import FreightCondFreeTypeEnum from "@/feature/pdt/infra/constants/FreightCondFreeTypeEnum";
import Id from "@/framework/infra/generator/Id";

const id = Id('FreightFeeArea')
export default class FreightFeeArea {
  constructor(props = {}) {
    this.feeArea = ''

    // this.firstWeight = 1
    this.firstNum = 1
    this.firstFee = 10

    // this.continueWeight = 0
    this.continueNum = 1
    this.continueFee = 0

    this.condFreeFlag = 1
    this.condFreeType = FreightCondFreeTypeEnum.NUM.id //
    this.condFreeNum = 3
    // this.chargeType = ChargeTypeEnum.NUM.id
    this.errMsg = ''
    this._key = id()
    Object.assign(this, props)
  }

  validate() {
    try {
      if (!this.feeArea) {
        throw new Error('请选择付费区域')
      }
      if (this.firstNum < 1) {
        throw new Error('首件/首重数量必须大于等于1')
      }
      if (this.firstFee <= 0) {
        throw new Error('首件/首重金额必须大于0')
      }
      if (this.continueNum < 1) {
        throw new Error('续件/续重数量必须大于等于1')
      }
      if (this.condFreeFlag === 1 && this.condFreeNum < 1) {
        throw new Error('条件包邮数量必须大于等于1')
      }
      this.errMsg = ''
    } catch (e) {
      this.errMsg = e.message
      throw e
    }
  }
}
